<?php

namespace app\shell;

use app\service\cache\DeviceGroupTableCacheService;
use app\service\cache\LocalDeviceInfoCacheService;
use app\service\cache\SendNoticeTableCacheService;
use app\service\cache\UserDeviceBindingCacheService;
use app\service\cache\UserDeviceShareCacheService;
use app\service\cache\VersionInfoCacheService;
use share\console\CLIRunner;
use share\service\cache\UserInfoAccountCacheService;
use share\service\cache\UserInfoCacheService;
use share\service\cache\UserPassCacheService;

class CCacheTest extends CLIRunner
{

    public static function test_device_group_action()
    {
        $filter = [
            // 存在的
            "user_id" => 'ede8aa97021ffbad9db32b037d67999b',
            "vendor" => 'ENZ',

            // // 存在的
            // "user_id" => 'ede8aa97021ffbad9db32b037d67999b',
            // "vendor" => 'ENZ',

            // // 不存在的
            // "user_id" => 'ede8aa97021ffbad9db32b037d6799',
            // "vendor" => 'EN',

            // // 不存在的
            // "user_id" => 'ede8aa97021ffbad9db32b037d67999b',
            // "vendor" => 'EN',
        ];
        // $res = DeviceGroupTableCacheService::getAllByFilter($filter);

        // DeviceGroupTableCacheService::reflush(['user_id'=>'ede8aa97021ffbad9db32b037d67999b','vendor'=>'ENZ']);
        // $res = DeviceGroupTableCacheService::getAllByFilter($filter);

        // DeviceGroupTableCacheService::reflush(['user_id'=>'87701b85e49ce4bef55bdc483e81042d']);

        // //不存在的
        // DeviceGroupTableCacheService::reflush(['user_id'=>'87701b85e49c81042d']);
        // $iotIds = [''];
        // $res = DeviceGroupTableCacheService::delByMainIds($iotIds);

        $userIds = ['87701b85e49ce4bef55bdc483e81042d', 'ede8aa97021ffbad9db32b037d67999b', '000'];
        $res = DeviceGroupTableCacheService::delAllByUserIds($userIds);
        return $res;
    }

    public static function test_local_device_action()
    {
        $userId = '87701b85e49ce4bef55bdc483e81042d';   // 无数据
        // $userId = '009d8b6c71dd6ab7274fe94c293213c7';    // 有数据

        $res = LocalDeviceInfoCacheService::reflush(['user_id' => $userId]);
        $res = LocalDeviceInfoCacheService::getAllByFilter(['user_id' => $userId]);
        return $res;
    }

    public static function test_send_notice_action()
    {        
        // $sendInfo = SendNoticeTableCacheService::getAllByFilter(['status'=> 1],['first_time','desc']);
        $sendInfo = SendNoticeTableCacheService::getAllByFilter(['status'=> 1,"language"=> 'CN'],['first_time','desc']);
        // SendNoticeTableCacheService::reflushAll();
        return $sendInfo;
    }

    public static function test_user_device_binding_action()
    {    
        // $filter = [
        //     'user_id' => '15aed27ebf866ef739718abfbf9dd215',
        //     'iot_id' => 'gvrhKwSpzHKkXYMvul8p000000', 
        // ];
        // // // $res = UserDeviceBindingCacheService::getAllByFilter($filter);

        // $res = UserDeviceBindingCacheService::reflush($filter);

        UserDeviceBindingCacheService::delAll();
        return ;
    }

    public static function test_user_device_share_by_device_action()
    {    
    }

    public static function test_user_device_share_action(){
        $filter = [
            'share_id' => '8d411d36208445966d8b892dc81cda23',
        ];
        $res = UserDeviceShareCacheService::getAllByFilter($filter);

        // $res = UserDeviceShareCacheService::reflush($filter);
        return $res;
    }

    public static function test_version_info_action(){
        $filter = [
            'type' => 'ios',
            'name' => 'com.enzhi.weilixin',
            'force' => "1"
        ];
        
        $res = VersionInfoCacheService::getOneByFilter($filter, ["version", "desc"]);


        // VersionInfoCacheService::reflushAll();
        // $res = UserDeviceShareCacheService::reflush($filter);
        return $res;
    }

    public static function test_user_info_action(){
        $uid = '00007d86c3290668dea57222597ecafc';
        // $res = UserInfoCacheService::getOneByFilter(['user_id' => $uid]);

        // $res = UserInfoCacheService::del(['user_id' => $uid]);

        $res = UserInfoCacheService::mget(['00051420327b4eb62f176df8289325b6']);
        return $res;
    }

    public static function test_user_info_account_action(){
        $uid = '00007d86c3290668dea57222597ecafc';
        $res = UserPassCacheService::getOneByFilter(['user_id' => $uid]);

        $res = UserPassCacheService::reflush(['user_id' => $uid]);
        // $res = UserInfoCacheService::reflush(['user_id' => $uid]);
        // $res = UserInfoCacheService::mget(['00051420327b4eb62f176df8289325b6']);
        return $res;
    }

    public static function test_user_pass_action(){

    }
}
